home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: MegaDisc / MegaDisc 34 (1993-06)(MegaDisc Digital Publishing)(AU)(Disk 1 of 2)[WB].zip / MegaDisc 34 (1993-06)(MegaDisc Digital Publishing)(AU)(Disk 1 of 2)[WB].adf / Programs / IntConv32 / itoa32.asm < prev    next >
Assembly Source File  |  1993-06-21  |  1KB  |  76 lines

  1. ; (C) 1993 Peter Thompson
  2. ; 32 (un|%)signed integer to base 10 string conversion.
  3.  
  4.     INCLUDE    "intdefs.i"
  5.  
  6.     IFD    ASM_ENTRY
  7.     INCLUDE    "intconv32.i"
  8.     ENDIF
  9.  
  10.     IFD    STKARGS
  11.     PUBLIC    _utoa32
  12. _utoa32:                ;C stkargs entry
  13.     move.l    8(sp),d0        ;C uint32
  14.     move.l    4(sp),a0        ;C char *
  15.     bra    ua32
  16.     ENDIF
  17.  
  18.     IFD    STKARGS
  19.     PUBLIC    _itoa32
  20. _itoa32:                ;C stkargs entry
  21.     move.l    8(sp),d0        ;C int32
  22.     move.l    4(sp),a0        ;C char *
  23.     ENDIF
  24.  
  25.     IFD    REGARGS
  26.     PUBLIC    @itoa32
  27. @itoa32:                ;C regargs entry
  28.     ENDIF
  29.  
  30. i2a32:    tst.l    d0
  31.     bpl    ua32
  32.     PutCh    #'-'
  33.     neg.l    d0
  34.  
  35.     IFD    REGARGS
  36.     PUBLIC    @utoa32
  37. @utoa32:                ;C regargs entry
  38.     ENDIF
  39.  
  40. u2a32:
  41. ua32:    ; converts 32 bit unsigned integer to base 10 string.
  42.     push    Dlim/Digit
  43.     lea    u32tbl(PC),Table
  44.     moveq    #8,Dlim        ; # of items in u32tbl - 1
  45. ls32:    cmp.l    (Table)+,d0    ; compare to table entries
  46.     dbcc    Dlim,ls32    ; until table <= number or out of table
  47.     add.w    #1,Dlim
  48.     beq    pru32a        ; 0-10 take this branch
  49.     subq.l    #4,Table    ; overshot : let's fix it.
  50. pru32a:    move.l    (Table)+,d1    ; print 32 bit unsigned integer.
  51.     moveq    #%00001111+'0',Digit
  52. pru32b:    sub.l    d1,d0        ; linear faster for dividend < 10.
  53.     dbcs    Digit,pru32b
  54.     add.l    d1,d0
  55.     eor.b    #%00001111,Digit    ; magic
  56.     PutCh    Digit
  57.     dbra    Dlim,pru32a
  58.     PutCh    #0            ; terminate string.
  59.     pop    Dlim/Digit
  60.     move.l    a0,d0            ;C return value
  61.     rts
  62.  
  63. u32tbl:    dc.l    $3B9ACA00
  64.     dc.l    $05F5E100
  65.     dc.l    $00989680
  66.     dc.l    $000F4240
  67.     dc.l    $000186A0
  68.     dc.l    $00002710
  69.     dc.l    $000003E8
  70.     dc.l    $00000064
  71.     dc.l    $0000000A
  72.     dc.l    $00000001
  73.  
  74.     END
  75.  
  76.